function [OPAM_COMPOSITION] = OPAM_Yang1996(DAT,P,inputElements,ElementIndicies4Target_IN,ElementIndicies4Target_OUT)


targetElements = {'SiO2' 'TiO2' 'Al2O3' 'Fe2O3' 'FeO' 'MgO' 'CaO' 'Na2O' 'K2O' 'P2O5' 'Cr2O3' 'MnO'}; 
%[A,ElementIndicies4Target] = ismember(targetElements, inputElements);


noData = find(ElementIndicies4Target_IN==0); 
ElementIndicies4Target_IN(ElementIndicies4Target_IN == 0) = max(ElementIndicies4Target_IN); 
newlyOrderedElements = DAT(:,ElementIndicies4Target_IN);
%pads rows of NaNs for elements with missing data
newlyOrderedElements(:,noData)=[0]; 
newlyOrderedElements(isnan(newlyOrderedElements))=0; 
DAT = newlyOrderedElements;  

% 1-SIO2 2-TIO2 3-AL2O3 4-FE2O3 5-FEO 6-MGO 7-CAO 8-NA2O 9-K2O 10-P2O5
% 11-CR2O3 12-MNO;


%%

MSIO2=DAT(1,1)/60.09;
MTIO2=DAT(1,2)/79.9;
MAL2O3=DAT(1,3)/102*2;
MFE2O3=DAT(1,4)/159.7*2;
MFEO=DAT(1,5)/71.85;
MMGO=DAT(1,6)/40.3;
MCAO=DAT(1,7)/56.08;
MNA2O=DAT(1,8)/62*2;
MK2O=DAT(1,9)/94.2*2;
MP2O5=DAT(1,10)/141.9*2;
MCR2O3=DAT(1,11)/152*2;
MTOTAL=MSIO2+MTIO2+MAL2O3+MFE2O3+MFEO+MMGO+MCAO+MNA2O+MK2O+MP2O5+MCR2O3;

MSIO2=MSIO2/MTOTAL;
MTIO2=MTIO2/MTOTAL;
MAL2O3=MAL2O3/MTOTAL;
MFE2O3=MFE2O3/MTOTAL;
MFEO=MFEO/MTOTAL;
MMGO=MMGO/MTOTAL;
MCAO=MCAO/MTOTAL;
MNA2O=MNA2O/MTOTAL;
MK2O=MK2O/MTOTAL;
MP2O5=MP2O5/MTOTAL;
MCR2O3=MCR2O3/MTOTAL;

HJAL2O3=0.236435+0.002182*P+0.109199*MNA2O+0.593295*MK2O-...
    0.349718*MTIO2-0.299419*MFEO-0.130353*MSIO2;
HJMGO=-0.276789+0.001139*P-0.542727*MNA2O-0.947294*MK2O-0.117029*MTIO2...
	-0.489758*MFEO+2.085584*MSIO2-2.400115*MSIO2^2;
HJCAO=1.132807-0.003388*P-0.569004*MNA2O-0.776108*MK2O-0.672285*MTIO2...
	-0.213801*MFEO-3.355327*MSIO2+2.830219*MSIO2^2;

OPAM_COMPOSITION = [MSIO2 MTIO2 HJAL2O3 MFE2O3 MFEO HJMGO HJCAO MNA2O MK2O MP2O5 MCR2O3];
WEIGHTS = [60.09 79.9 102/2 159.7/2 71.85 40.3 56.08 62/2 94.2/2 141.9/2 152/2];
OPAM_COMPOSITION = 100.*OPAM_COMPOSITION.*WEIGHTS./sum(OPAM_COMPOSITION.*WEIGHTS); 




% ElementsYANG = {'SiO2' 'TiO2' 'Al2O3' 'Fe2O3' 'FeO' 'MgO' 'CaO' 'Na2O' 'K2O' 'P2O5' 'Cr2O3'}; 
% [A,ElementIndicies4Target_OUT] = ismember(inputElements, ElementsYANG);


noData = find(ElementIndicies4Target_OUT==0); 
ElementIndicies4Target_OUT(ElementIndicies4Target_OUT == 0) = max(ElementIndicies4Target_OUT); 
newlyOrderedElements = OPAM_COMPOSITION(:,ElementIndicies4Target_OUT);
%pads rows of NaNs for elements with missing data
newlyOrderedElements(:,noData)=[0]; 
newlyOrderedElements(isnan(newlyOrderedElements))=0; 
OPAM_COMPOSITION = newlyOrderedElements;  



end


